package dreampharos.util;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import dreampharos.dto.MemberDTO;

public class SessionUtil {

	public boolean SessionValue(HttpServletRequest request, String sessionName) {		
		boolean flag = false;
		
		HttpSession session = null;
		session = request.getSession();
		
		if(session != null && session.getAttribute(sessionName) != null) {
			flag = true;
		} else {
			flag = false;
		}
		
		return flag;
	}
	
	public String SessionValue(HttpServletRequest request, String sessionName, String name) {
		String returnVal = null;
		
		if(SessionValue(request, sessionName)) {
			HttpSession session = null;
			session = request.getSession();
			
			MemberDTO sessionBean = new MemberDTO();
			sessionBean = (MemberDTO)session.getAttribute(sessionName);
			
			if("user_id".equals(name)) {
				returnVal = sessionBean.getId();
			} else if("user_name".equals(name)) {
				returnVal = sessionBean.getName();
			} else {
				returnVal = "";
			}
		} else {
			returnVal = "";
		}
		
		return returnVal;
	}
}
